package cn.iocoder.yudao.module.dt.controller.admin.tenantinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dt.controller.admin.tenantinfo.vo.*;
import cn.iocoder.yudao.module.dt.dal.dataobject.tenantinfo.TenantInfoDO;
import cn.iocoder.yudao.module.dt.convert.tenantinfo.TenantInfoConvert;
import cn.iocoder.yudao.module.dt.service.tenantinfo.TenantInfoService;

@Api(tags = "管理后台 - 俱乐部信息表，用作小程序首页展示")
@RestController
@RequestMapping("/dt/tenant-info")
@Validated
public class TenantInfoController {

    @Resource
    private TenantInfoService tenantInfoService;

    @PostMapping("/create")
    @ApiOperation("创建俱乐部信息表，用作小程序首页展示")
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:create')")
    public CommonResult<Integer> createTenantInfo(@Valid @RequestBody TenantInfoCreateReqVO createReqVO) {
        return success(tenantInfoService.createTenantInfo(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新俱乐部信息表，用作小程序首页展示")
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:update')")
    public CommonResult<Boolean> updateTenantInfo(@Valid @RequestBody TenantInfoUpdateReqVO updateReqVO) {
        tenantInfoService.updateTenantInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除俱乐部信息表，用作小程序首页展示")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:delete')")
    public CommonResult<Boolean> deleteTenantInfo(@RequestParam("id") Integer id) {
        tenantInfoService.deleteTenantInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得俱乐部信息表，用作小程序首页展示")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:query')")
    public CommonResult<TenantInfoRespVO> getTenantInfo(@RequestParam("id") Integer id) {
        TenantInfoDO tenantInfo = tenantInfoService.getTenantInfo(id);
        return success(TenantInfoConvert.INSTANCE.convert(tenantInfo));
    }

    @GetMapping("/list")
    @ApiOperation("获得俱乐部信息表，用作小程序首页展示列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:query')")
    public CommonResult<List<TenantInfoRespVO>> getTenantInfoList(@RequestParam("ids") Collection<Integer> ids) {
        List<TenantInfoDO> list = tenantInfoService.getTenantInfoList(ids);
        return success(TenantInfoConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得俱乐部信息表，用作小程序首页展示分页")
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:query')")
    public CommonResult<PageResult<TenantInfoRespVO>> getTenantInfoPage(@Valid TenantInfoPageReqVO pageVO) {
        PageResult<TenantInfoDO> pageResult = tenantInfoService.getTenantInfoPage(pageVO);
        return success(TenantInfoConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出俱乐部信息表，用作小程序首页展示 Excel")
    @PreAuthorize("@ss.hasPermission('dt:tenant-info:export')")
    @OperateLog(type = EXPORT)
    public void exportTenantInfoExcel(@Valid TenantInfoExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<TenantInfoDO> list = tenantInfoService.getTenantInfoList(exportReqVO);
        // 导出 Excel
        List<TenantInfoExcelVO> datas = TenantInfoConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "俱乐部信息表，用作小程序首页展示.xls", "数据", TenantInfoExcelVO.class, datas);
    }

}
